
function sleep(millis) {
var future = new Future();
setTimeout(future.fulfill, millis);
future.result();
}

function Lock() {
	var future = new Future();

	this.wait = function() {
		future.result();
	}
	
	this.notify = function() {
		future.fulfill();
	}
}

function go () {
document.getElementById("txtr").innerHTML += "1" ;
sleep(2000);
document.getElementById("txtr").innerHTML += "2" ;

}

function go2 () {
	var l = new Lock();
	
	document.getElementById("txtr").innerHTML = "blocking...";

	setTimeout(function() { l.notify(); }, 3000);

	l.wait();	
	document.getElementById("txtr").innerHTML = "unblocked";
}


new Future(go2);